package com.msb.strategy.mq;

import com.msb.common.constart.RabbitMQConstants;
import com.msb.common.exception.ApiException;
import com.msb.common.model.StandardSubmit;
import com.msb.strategy.filter.StrategyFilterContext;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 监听接口模块推送过来的消息
 *
 * @Author: lmf
 * @Create: 2025/3/11 21:51
 * @module
 */
@Component
@Slf4j
public class PerSendListener {
    @Resource
    StrategyFilterContext strategyFilterContext;

    @RabbitListener(queues = RabbitMQConstants.SMS_PRE_SEND)
    public void listener(StandardSubmit submit, Message msg, Channel channel) {
        try {
            log.info("【接口模块-发送消息】 接收到消息 message={}", submit);
//            // 业务
            strategyFilterContext.strategy(submit);
            log.info("消费完毕手动确认消息");
            channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
            log.info("endTime:{}=========>>>>>>", System.currentTimeMillis());

        } catch (IOException | ApiException e) {
            log.error("【接口模块-发送消息】 消费消息失败 submit={},e={}", submit, e.getMessage());
        }
    }
}
